package rxjava;


import io.reactivex.Flowable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

import java.util.concurrent.Callable;

/**
 * Created by Administrator on 2017-03-14.
 */
public class BaseRx {


    public static void main(String arg[]) {
//        Flowable.just("Hello world").subscribe(System.out::println);

        /*Flowable.just("Hello world")
                .subscribe(new Consumer<String>() {
                               @Override
                               public void accept(String s) {
                                   System.out.println(s);
                               }
                           }
                );*/

        Flowable.fromCallable(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(1000); //  imitate expensive computation
                return "Done";
            }
        }).subscribeOn(Schedulers.io())
                .observeOn(Schedulers.single())
                .subscribe(System.out::println, Throwable::printStackTrace);

        try {
            Thread.sleep(2000); // <--- wait for the flow to finish
        } catch (InterruptedException e) {
            e.printStackTrace();
        }



    }

}
